<!DOCTYPE html>
<html >
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>学生信息管理平台</title>
	<link href="../../Style/StudentStyle.css" rel="stylesheet" type="text/css" />
	<link href="../../Script/jBox/Skins/Blue/jbox.css" rel="stylesheet" type="text/css" />
	<link href="../../Style/ks.css" rel="stylesheet" type="text/css" />
	<link href="../../css/mine.css" type="text/css" rel="stylesheet">
	<script src="../../Script/jBox/jquery-1.4.2.min.js" type="text/javascript"></script>
	<script src="../../Script/jBox/jquery.jBox-2.3.min.js"
			type="text/javascript"></script>
	<script src="../../Script/jBox/i18n/jquery.jBox-zh-CN.js"
			type="text/javascript"></script>
	<script src="../../Script/Common.js" type="text/javascript"></script>
	<script src="../../Script/Data.js" type="text/javascript"></script>

	<script>
		function del(){
			confirm("确认操作？");
		}

	</script>



</head>
<body>

<div class="div_head" style="width: 100%;text-align:center;">
		<span>
                <span style="float: left;">当前位置是：教务中心-》学生管理</span>
                <span style="float: right; margin-right: 8px; font-weight: bold;">
                    <a style="text-decoration: none;" href="/Educational/student/add.html">【新增学生】</a>&emsp;&emsp;&emsp;&emsp;
                </span>
            </span>
</div>

<div class="cztable">
	<div>
		<form id="myForm" action="/Educational/student/studentServlet" method="get">
			学生名称:
			<input type="text" name="stuName" value=""/>
			学生学号:
			<input type="text" name="stuNo" value=""/>
			性别:
			<select name="sex">
				<option value="-1">--请选择--</option>
				<option value="1" ${sex=='1'?"selected":""}>男</option>
				<option value="0" ${sex=='0'?"selected":""}>女</option>
			</select>
			<button type="button" id="btn1" onclick="loadData()">查询</button>
			<button style="margin-left: 20px" type="reset" >重置</button>
		</form>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tbody id="myTbody">
			<!--				<tr style="height: 25px" align="center">-->
			<!--                        <th >学号</th>-->
			<!--						<th width="">姓名</th>-->
			<!--						<th width="">性别</th>-->
			<!--                        <th width="15%">联系电话</th>-->
			<!--                        <th width="15%">专业</th>-->
			<!--						<th width="15%">登记时间</th>-->
			<!--						<th>操作</th>-->
			<!--                    </tr>-->
			</tbody>
		</table>
	</div>

</div>
</div>

</div>
</body>
</html>
<script>
	let pageNum;
	let pages;
	let pageSize;
	$(function () {
		readUrl();
		if(pageNum==null){
			pageNum=1;
		}
		if(pageSize==null){
			pageSize=5;
		}
		loadData();

	});
	//加载数据

	function firstPage() {
		pageNum=1;
		loadData();
	}
	function prePage() {
		pageNum=pageNum-1>0?pageNum-1:1;
		loadData();
	}
	function nextPage() {
		pageNum=pageNum+1>pages?pages:pageNum+1;
		loadData();
	}
	function lastPage() {
		pageNum=pages;
		loadData();
	}
	function loadData(){
		//alert($("#myForm").serialize())
		//pageNum = $("#pageNum").html();
		//let pageSize = $("#pageSize").html();

		$.ajax({
			type: "GET",
			url: "/student/list",
			data: $("#myForm").serialize()+"&pageNum="+pageNum+"&pageSize="+pageSize,//主要是分页和多条件参数数据
			dataType: "json",
			success: function (vo) {
				//alert( "Data Saved: " + vo );
				let list = vo.pageInfo.list;
				let pageInfo=vo.pageInfo;
				let total=pageInfo.total;
				pages=pageInfo.pages;
				pageNum=pageInfo.pageNum;
				pageSize=pageInfo.pageSize;
				let str1 = "<tr style=\"height: 25px\" align=\"center\">\n" +
						"                        <th >学号</th>\n" +
						"\t\t\t\t\t\t<th width=\"\">姓名</th>\n" +
						"\t\t\t\t\t\t<th width=\"\">性别</th>\n" +
						"                        <th width=\"15%\">联系电话</th>\t\t\t\t\t\t\n" +
						"                        <th width=\"15%\">专业</th>\n" +
						"\t\t\t\t\t\t<th width=\"15%\">登记时间</th>\n" +
						"\t\t\t\t\t\t<th>操作</th>\n" +
						"                    </tr>";
				$("#myTbody").html(str1);
				for (let i = 0; i < list.length; i++) {
					let obj = list[i];
					let stuId=obj.stuId;
					let stuNo = obj.stuNo == null ? '' : obj.stuNo;
					let stuName = obj.stuName == null ? '' : obj.stuName;
					let sex = obj.sex == 1 ? '男' : '女';
					let phone = obj.phone == null ? '' : obj.phone;
					let profession = obj.profession == null ? '' : obj.profession;
					let regdate = obj.regdate == null ? '' : obj.regdate;

					str = " <tr id=\"product1\">\n" +
							"                        <td align=\"center\">"+stuNo+"</td>\n" +
							"\t\t\t\t\t\t<td align=\"center\">"+stuName+"</td>\n" +
							"\t\t\t\t\t\t<td align=\"center\">"+sex+"</td>\n" +
							"                        <td align=\"center\">"+phone+"</td>\n" +
							"\t\t\t\t\t\t<td align=\"center\">"+profession+"</td>\n" +
							"                        <td align=\"center\">"+regdate+"</td>\n" +
							"\t\t\t\t\t\t<td align=\"center\">\n" +
							"\t\t\t\t\t\t\t<button type='button' onclick='updateStudent("+stuId+")'>修改</button>\n" +
							"\t\t\t\t\t\t\t<button type='button' onclick='deleteStudent("+stuId+")'>删除</button>\n" +
							"\t\t\t\t\t\t\t<button type='button' onclick='findStudent("+stuId+")'>详情</button>\n" +
							"\t\t\t\t\t\t</td> \t\t\t\t \n" +
							"                    </tr>";
					$("#myTbody").append(str);
				}
				let pageDate = "\n" +
						"                    <tr>\n" +
						"                        <td colspan=\"20\" style=\"text-align: center;\">\t\t\t\t\t\t\n" +
						"\t\t\t\t\t\t<a style=\"text-decoration: none;\" href='javascript:firstPage()'>\n" +
						"                            首页</a>\n" +
						"\t\t\t\t\t\t\t<a style=\"text-decoration: none;\" href='javascript:prePage()'>\n" +
						"\t\t\t\t\t\t\t\t上一页</a>\n" +
						"\t\t\t\t\t\t\t<a style=\"text-decoration: none;\" href='javascript:nextPage()'>\n" +
						"\t\t\t\t\t\t\t\t下一页</a>\n" +
						"\t\t\t\t\t\t\t<a style=\"text-decoration: none;\"  href='javascript:lastPage()'>\n" +
						"\t\t\t\t\t\t\t\t尾页</a> 共"+total+"条 每页显示<span id='pageSize'>"+pageSize+"</span>条&nbsp;&nbsp;第<span id='pageNum'>"+pageNum+"</span>页/共"+pages+"页\n" +
						"                        </td>\n" +
						"                    </tr>";

				$("#myTbody").append(pageDate);

			}
		});
	}

	function findStudent(id){
		window.location.href="/Educational/student/info.html?stuId="+id;

	}
	//更新按钮
	function updateStudent(id) {
		let pageNum=$("#pageNum").html();
		let pageSize=$("#pageSize").html();
		window.location.href="/Educational/student/edit.html?stuId="+id+"&pageNum="+pageNum+"&pageSize="+pageSize;
	}
	//删除按钮
	function deleteStudent(id) {
		if(confirm("确定要删除吗?")) {
			//发起异步请求
			$.ajax({
				type: "POST",
				url: "/student/" + id, //RESTful风格的API定义
				data: "_method=DELETE",
				success: function (vo) {
					if(vo.code==200){
						alert("删除成功!");
						loadData();
					}else{
						alert(vo.msg);
					}
				}
			});
		}
	}
	function readUrl() {
		let url = document.location.toString();
		let pageNum1=url.GetValue("pageNum");
		let pageSize1=url.GetValue("pageSize");
		if(pageNum1!=null){
			pageNum=pageNum1;
		}
		if(pageSize1!=null){
			pageSize=pageSize1;
		}
	}
	String.prototype.GetValue= function(para) {
		let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
		let r = this.substr(this.indexOf("\?")+1).match(reg);
		if (r!=null) return unescape(r[2]); return null;
	}

</script>